package com.example.myframeanimation;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.RelativeLayout;

public class MainActivity extends AppCompatActivity {

    private Boolean flag = Boolean.TRUE;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 获取布局对象
        RelativeLayout rlMain = findViewById(R.id.rl_main);
        AnimationDrawable animationDrawable = (AnimationDrawable) rlMain.getBackground();
        // 设置点击事件
        rlMain.setOnClickListener(v -> {
            if (flag) {
                animationDrawable.start();
                flag = false;
            } else {
                animationDrawable.stop();
                flag = true;
            }
        });
    }
}